import axios from "axios"
import URLConfig from "../config/url"
import {Toast, MessageBox} from 'mint-ui'

function createPromise(url, params = {}, method = 'get') {
  let options = {
    method: method,
    url: URLConfig(url),
    // headers: {
    //   'Content-Type': 'multipart/form-data'
    // }
  }
  if(method=='get'){
    options.params = params
  }else{
    options.data = params
  }
  return axios(options).then((res) => {
    if (res.status != 200 || res.data.code != 0) {
      Toast({
        message: res.data.message,
        position: 'bottom',
        duration: 3000
      })
      return void 0
    }else{
      return res.data
    }
  }).catch((er) => {
    MessageBox('提示', '系统错误，请稍后再试');
  });
}

export {
  createPromise
}